package com.niit.order.web;

import com.niit.order.pojo.Order;
import com.niit.order.pojo.User;
import com.niit.order.service.IOrderService;
import com.niit.order.service.MyUserClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 使用自定义的MyUserClient进行演示
 * 与使用Feign-api的案例不能同时存在,会冲突
 * @author yaojianfeng
 */

@RestController
@RequestMapping("/myFeign")
public class MyFeignDemoController {
    @Autowired
    private IOrderService onlyOrder;
    @Autowired
    private MyUserClient myUserClient;

    @GetMapping("/order/{orderId}")
    public Order queryOrderByUserId(@PathVariable("orderId") Long orderId) {
        // 根据id查询订单并返回
        Order order = onlyOrder.queryOrderById(orderId);
        // 使用Feign 封装的客户端
        User forObject = myUserClient.findUserById(order.getUserId() + "");
        //封装返回的数据
        order.setUser(forObject);
        return order;
    }

    @GetMapping("/order/request")
    public String requestParamDemo(@RequestParam String param) {
        return myUserClient.requestParam(param);
    }

    @GetMapping("/order/header")
    public User headerInfo(@RequestHeader String name, @RequestHeader String address) {
        return myUserClient.headerInfo(name, address);
    }

    @GetMapping("/order/body")
    public String bodyInfo(@RequestBody User user) {
        return myUserClient.bodyInfo(user);
    }
}
